// pages/orderLogs/orderLogs.js
var verify = require('../../../../utils/verify-token.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
		date:'',
		page:0,
		totalPage:0,
		loaded:false,
		loading:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {	
		var date = options.date;
    this.setData({
      screenHeight: app.globalData.screenHeight,
      screenWidth: app.globalData.screenWidth,
			date:date
    });
		this.getlogList();
  },
	
	getlogList:function(){
		var thm = this;
		var dat = {
			date:thm.data.date,
			size:10,
			page:thm.data.page
		};		
		wx.request({
		  url: app.globalData.baseUrl+'orderRec/getChargeRecByOneDay',
		  method: 'get',
		  header:{
		    'AUTHORIZATION':app.globalData.token
		  },
			data:dat,
		  success: function (res) {
        if (res.data.code == 60006) {
          verify.clearAll()
        } else if(res.data.code==200){
					var listdata = res.data.data.content;
          // console.log("listdata = ", listdata)
          var orderDate
          var length
          var time = ""
          for(var i = 0;i<listdata.length;i++){
            orderDate = listdata[i].orderDate
            length = orderDate.length
            for(var j = 0;j<8;j++){
              time = orderDate[length-j-1]+time
            }
            listdata[i].orderDate = time
            time = ""
          }
					var listD = thm.data.list;
					var ldh = listD.length;
					for(var i=0;i<listdata.length;i++){
						listD[ldh+i] = listdata[i]
					}
				  thm.setData({
						list:listD,
						totalPage:res.data.data.totalPages,
						loading:res.data.data.last?false:true,
						loaded:res.data.data.last?true:false
				  })
		    }
		  }
		})
		
	},
  detail: function (ev) {	
    wx.navigateTo({
      url: '../detail/detail?data='+JSON.stringify(ev.currentTarget.dataset),
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
		
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
		// var that = this;
		// that.setData({
		// 	list:[],
		// 	page:0,
		// 	totalPage:0,
		// });
		// that.getlogList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
		wx.stopPullDownRefresh;

		console.log(12345)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
		var that=this;
		var page = that.data.page + 1; 
		if(page<=that.data.totalPage-1){	
			that.setData({
				page: page, 
			})					
			that.getlogList();
		}else{
			that.setData({
				loaded:true,
				loading:false
			})
		}
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})